<?php
	class userControl extends rbacControl{
		function index(){
			/* $db=M("user");
			$count = $db->count();
			$page = new page($count,6);
			$row=$db->field("uid,username,password,email,logintime")->limit($page->limit())->all(); */
			$db=K("userview");$count = $db->count();$page = new page($count,3);
			$row=$db->field("user.uid,username,email,logintime,rname,title")->limit($page->limit())->all(); 
			//p($row);
			if (!$row) {
				$this->error("没有任何组(角色)信息，请先设置", "user_add_show");
			}
			$this->assign("row",$row);
			 $this->assign("page", $page->show(2));
			$this->display();
		}
		function user_add_show(){
			//echo "添加用户";
			$db=M("role");
			$role=$db->all();
			$this->assign("role",$role);
			$this->display();
		}
		function user_add(){
			$_POST['password']=md5($_POST['password']);
			//p($_POST);exit;
			$db=K("userrelation");
			$username = $_POST['username'];
			$row = $db->where("username='$username'")->select();
			if($row){
				$this->error('用户已经存在，请重新填写用户名');
			}else{
				$db->add();
				$this->success("添加用户成功");
			}
		}
		function user_del(){
			$uid=$_GET['id'];
			$db=K("userrelation");
			if($db->where("uid=$uid")->del()){
				$this->success("删除用户成功！");
			}else{
				$this->error("删除用户失败！");
			}
		}
		function user_edit_show(){
			$uid=$_GET["id"];
			$db=K("userrelation");
			$row=$db->where("uid=$uid")->find();
			$db=M("role");
			$role=$db->all();
			$this->assign("role",$role);
			$this->assign("row",$row);
			$this->display();
		}
		function user_save(){
			$uid=$_GET["uid"];
			$_POST["uid"]=$uid;
			$_POST['password']=md5($_POST['password']);
			$db = K("userrelation");
			if($db->save()){
				$this->success("用户信息修改成功");
			}else{
				$this->error("用户信息修改失败");
			}
		
		}
		
		
	}
?>